package com.abacus.pos.base

import android.content.Context
import android.content.DialogInterface
import android.os.Bundle
import android.view.inputmethod.InputMethodManager
import androidx.fragment.app.DialogFragment
import com.abacus.pos.R




/**
 * User: highsixty
 * Date: 2020/5/8 13:49
 * email: gaolulin@sunmi.com
 * 统一实现弹窗隐藏状态栏、设置默认透明背景
 */
open class BaseDialogFragment : DialogFragment() {
    /**
     * DialogFragment隐藏监听
     */
    var onDismissListener: (() -> Unit)? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setStyle(STYLE_NO_FRAME, R.style.FullScreenDialog)
    }




    fun showDialog() {
        (activity as BaseActivity<*>).showDialog()
    }

    fun hideDialog() {
        (activity as BaseActivity<*>).hideDialog()
    }

    override fun onDestroyView() {
        super.onDestroyView()
    }

    override fun onDismiss(dialog: DialogInterface) {
        super.onDismiss(dialog)
        onDismissListener?.invoke()
    }

    /**
     * 隐藏软键盘
     */
    fun hideSoftInput() {
        val imm = activity?.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
        imm.hideSoftInputFromWindow(dialog?.window?.decorView?.windowToken, 0)
    }
}